#include<iostream>
#include<algorithm>
using namespace std;
const int N = 310, M = 1e5 + 10;
int p[N];
int n, m;
int ans;
struct node
{
	int a, b, w;
}s[M];
int cmp(node a, node b)
{
	return a.w < b.w;
}
int find(int x)
{
	if (x != p[x])p[x] = find(p[x]);
	return p[x];
}
void kruskal()
{
	sort(s, s + m, cmp);
	for (int i = 1; i <= n; i++)p[i] = i;
	int cnt = 0;
	for (int i = 0; i < m; i++) {
		int a = find(s[i].a);
		int b = find(s[i].b);
		if (a != b) {
			p[a] = b;
			ans = max(ans, s[i].w);
			cnt++;
			if (cnt == n - 1)return;
		}
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b, v;
		cin >> a >> b >> v;
		s[i] = { a,b,v };
	}
	kruskal();
	cout << n - 1 << " ";
	cout << ans << endl;
	return 0;
}